﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using Memo.Electricity.Engine;

namespace Memo.Electricity.Game
{
    public class ProcessBarController : MemoBehaviour
    {
        //public float processSpeed = 0.2f;
        public float fadeOutSpeed = 5f;

        private Slider processBarSlider;
        private ParticleSystem processBarParticle;
        private Image fillImage;
        private Color particularColor;
        private float targetValue = 0f;
        private float currentValue = 1f;

        private void Awake()
        {
            processBarSlider = GetComponent<Slider>();
            fillImage = GameObject.Find("Fill").GetComponent<Image>();
            processBarParticle = GameObject.Find("ProcessBarParticular").GetComponent<ParticleSystem>();
        }

        // Start is called before the first frame update
        private void Start()
        {
            Debug.Log(PlayerManager.Inst.BatteryPer);
            processBarSlider.value = PlayerManager.Inst.BatteryPer;
            processBarParticle.Play();
        }

        // Update is called once per frame
        private void Update()
        {
            processBarSlider.value = PlayerManager.Inst.BatteryPer;           
            // if(processBarSlider.value <= 0)
            // {
            //     processBarParticle.Stop();
            //     FadeOutEffect(fadeOutSpeed);
            // }
                
        }

        // private void FadeOutEffect(float fadeSpeed)
        // {
        //     if (fillImage.color.a > 0)
        //     {
        //         fillImage.color -= new Color(0, 0, 0, fadeSpeed * Time.deltaTime);
        //     }
        //     else
        //     {
        //         RegisterOnce(() => gameObject.SetActive(false), 0.5f);
        //         //gameObject.SetActive(false);
        //     }
        // }

        // private void FadeOutEffect(GameObject gameObject, Color color, float fadeSpeed)
        // {
        //     if (color.a > 0)
        //     {
        //         color -= new Color(0, 0, 0, fadeSpeed * Time.deltaTime);
        //     }
        //     else
        //     {
        //         gameObject.SetActive(false);
        //     }
        // }
    }
}